<template>
  <div class="page-contact-info">
    <Navbar title="联系人" />
    <div class="content">
      <div class="avatar">{{ initial }}</div>

      <div class="user-name">{{ userInfo?.realName }}</div>
      <div class="user-pos" v-show="userInfo?.postName">{{ userInfo?.postName }}</div>
      <div class="user-org" v-show="userInfo?.strDeptName">{{ userInfo?.strDeptName }}</div>

      <div class="tel-info">
        <div class="tel-name">手机</div>
        <div class="tel">{{ userInfo?.mobile }}</div>
        <div class="icon">
          <a :href="mobileLink">
            <img src="./assets/phone.png" />
          </a>
        </div>
      </div>

      <div class="tel-info" v-if="telLink">
        <div class="tel-name">座机</div>
        <div class="tel">{{ userInfo?.ywMobile }}</div>
        <div class="icon">
          <a :href="telLink">
            <img src="./assets/phone.png" />
          </a>
        </div>
      </div>
    </div>
    <div class="btn-send" @click="handleSendClick">
      <img src="./assets/send-msg.png" />
      <span>发消息</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import ContactServe from '@/api/contact.ts'
import Navbar from '@/components/Navbar/index.vue'

const route = useRoute()
const router = useRouter()

const userInfo = ref<NullAble<IContactor>>(null)

const initial = computed(() => {
  if (userInfo.value) return userInfo.value.realName.slice(0, 1)
  return ''
})

const telLink = computed(() => {
  if (userInfo.value) return 'tel://' + userInfo.value.ywMobile
  return ''
})

const mobileLink = computed(() => {
  if (userInfo.value) return 'tel://' + userInfo.value.mobile
  return ''
})

const fetchUserInfo = () => {
  const { id } = route.query
  // TODO fetch user info
  ContactServe.userDetail({ id: id as string }).then(resp => {
    const { code, data } = resp
    if (code == 0) {
      userInfo.value = data
    }
  })
}

fetchUserInfo()

const handleSendClick = () => {
  router.push({
    path: '/contact/talk',
    query: {
      id: userInfo.value?.id,
      initial: initial.value
    }
  })
}
</script>

<style lang="less" scoped>
.page-contact-info {
  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0px 12px;

    .avatar {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      background-color: #3a75c5;
      color: #fff;
      font-size: 24px;
      margin-top: 20px;
      text-align: center;
      line-height: 80px;
      flex-shrink: 0;
    }

    .user-name {
      color: #212121;
      font-size: 21px;
      font-weight: bold;
      margin-top: 9px;
    }

    .user-pos {
      font-size: 11px;
      color: #3a75c5;
      background: #3a75c519;
      border-radius: 1.5px;
      padding: 1.5px 6px;
      line-height: 1;
      margin-top: 6px;
    }

    .user-org {
      width: 300px;
      text-align: center;
      line-height: 1;
      font-size: 13px;
      color: #2121217f;
      margin-top: 11px;
    }

    .tel-info {
      display: flex;
      align-items: center;
      width: 100%;
      background: #fff;
      height: 48px;
      border-radius: 8px;
      padding: 0px 12px;
      margin-top: 24px;
      box-sizing: border-box;
      .tel-name {
        color: #21212199;
        font-weight: medium;
        font-size: 14px;
        margin-right: 32px;
      }

      .tel {
        color: #212121;
        font-weight: medium;
        font-size: 14px;
        flex-grow: 1;
      }

      .icon {
        img {
          width: 48px;
          height: 28px;
        }
      }
    }
  }
  .btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 25px;
    background: #3a75c5;
    box-shadow: 0px 2px 5px 0px #00000019;
    height: 44px;
    position: fixed;
    bottom: 36px;
    width: 320px;
    margin-left: 27.5px;

    color: #ffffff;
    font-weight: bold;
    font-size: 16px;

    img {
      width: 22px;
      height: 22px;
      margin-right: 5px;
    }
  }
}
</style>
